package com.menhai.personmanagement.services;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.menhai.personmanagement.entity.EducationLog;
import com.menhai.personmanagement.entity.User;
import com.menhai.personmanagement.mapper.EducationLogMapper;
import com.menhai.personmanagement.mapper.UserMapper;
import com.menhai.personmanagement.plus.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学历信息 服务类
 * </p>
 *
 * @author shikun
 * @since 2021-12-02
 */
 @Service
public class IEducationLogService{

   @Autowired
   private EducationLogMapper educationLogMapper;

   @Autowired
   private UserMapper userMapper;


   /**
    * @describe 删除医生得学历
    * @param educationLog
    * @Return int
    * @Date 2021/12/6 9:18
    * @author shikun
    */
    public int deleteById(EducationLog educationLog){
     return educationLogMapper.deleteById(educationLog.getEducationid());
    }

    /**
     * @describe 根据医生id 查询学历
     * @param educationLog
     * @Return java.util.List<com.menhai.personmanagement.entity.EducationLog>
     * @Date 2021/12/6 9:35
     * @author shikun
     */
    public List<EducationLog> EducationLogByUserIdList(EducationLog educationLog){

     //QueryWrapper<EducationLog> educationLogQueryWrapper = new QueryWrapper<>();

     //educationLogQueryWrapper.lambda().eq(EducationLog::getUserid,educationLog.getUserid());

     //return educationLogMapper.selectList(educationLogQueryWrapper);

     return educationLogMapper.selectByuserid(educationLog.getUserid());

    };

     /**
      * @describe 根据学历id 查询学历实体
      * @param educationLog
      * @Return java.util.List<com.menhai.personmanagement.entity.EducationLog>
      * @Date 2021/12/6 11:22
      * @author shikun
      */
    public List<EducationLog> selectByeducationid(EducationLog educationLog){

     return educationLogMapper.selectByeducationid(educationLog.getEducationid());

    };


    /**
     * @describe 新增医生学历
     * @param educationLog
     * @Return int
     * @Date 2021/12/6 14:27
     * @author shikun
     */
    public int inserteducationLog(EducationLog educationLog){
     educationLog.setCtime(DateUtils.getLocalTime());
     userMapper.updateById(User.builder().id(educationLog.getUserid()).audit("1").build());
     return educationLogMapper.insert(educationLog);
    };


    /**
     * @describe 根据学历id 修改医生学历
     * @param educationLog
     * @Return int
     * @Date 2021/12/6 14:49
     * @author shikun
     */
    public int updateByIdeducationLog(EducationLog educationLog){
     userMapper.updateById(User.builder().id(educationLog.getUserid()).audit("1").build());
     return educationLogMapper.updateById(educationLog);
    }

}
